package com.gaga.metadata.convert;


import com.gaga.metadata.common.enums.ColumnType;
import com.gaga.metadata.entity.database.DataBaseColumn;

/**
 * ITypeConvert
 *
 * @author liujia
 * @since 2021/7/20 14:39
 **/
public abstract class AbstractDataTypeConvert implements IDataTypeConvert {


    @Override
    public String getColumnFullInfo(DataBaseColumn column) {
        StringBuilder sb = new StringBuilder();
        sb.append(column.getName().toLowerCase() + " " + getColumnTypeFullInfo(column));
        return sb.toString();
    }

    @Override
    public String getColumnTypeFullInfo(DataBaseColumn column) {

        ColumnType columnType = column.getColumnType();
        String type = convertToDB(column);
        switch (columnType) {
            case DECIMAL:
                type += "(" + column.getPrecision() + "," + column.getScale() + ")";
                break;
            case NUMBER:
                if (column.getScale().intValue() > 0) {
                    type += "(" + column.getPrecision() + "," + column.getScale() + ")";
                }
                break;
            case STRING:
                type += "(" + column.getPrecision() + ")";
                break;
            default:
                break;
        }
        return type;
    }


}
